<%@ page import="com.anbow.courseware.service.impl.TeachingQuestionsServiceImpl" %>
<%@ page import="com.anbow.courseware.entity.DTO.TeachingQuestionsDTO" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: zhaoYuFei
  Date: 2023/7/14
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- 引入chart -->
<script src="http://code.highcharts.com/highcharts.js"></script>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css" rel="stylesheet">
<!-- bootstrap-table.min.js -->
<script src="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<!-- 头部导航栏 -->
<jsp:include page="top.jsp" flush="true"/>

<div class="container-fluid">
    <div class="row">

        <!--左边菜单栏-->
        <jsp:include page="left.jsp" flush="true">
            <jsp:param name="ifDorAdActive" value="active"/>
        </jsp:include>

        <div class="col-sm-10">
            <!-- 顶部搜索部分 -->
            <div class="panel panel-default">
                <div class="panel-heading">搜索</div>
                <div class="panel-body">
                    <form role="form" class="form-inline"
                          action="<%= request.getContextPath()%>/teachingQuestions/getByLabel">
                        <div class="form-group" style="margin-left: 20px">
                            <label for="value">标签</label> <input type="text"
                                                                 class="form-control" id="value" name="label"
                                                                 placeholder="标签值"
                                                                 maxlength="12" style="width: 230px">
                        </div>
                        <div class="form-group " style="margin-left: 20px">
                            <button type="submit" class="btn btn-info ">
										<span style="margin-right: 5px"
                                              class="glyphicon glyphicon-search" aria-hidden="true">
										</span>开始搜索
                            </button>
                        </div>
                        <div class="form-group " style="margin-left: 20px">
                            <button id="emptys" type="button" class="btn btn-default"
                                    onclick="empty()">
										<span style="margin-right: 5px"
                                              class="glyphicon glyphicon-list" aria-hidden="true"> </span>刷新
                            </button>
                        </div>
                        <div class="form-group " style="margin-left: 48px">
                            <button type="button" class="btn btn-default"
                            >
											<span style="margin-right: 5px" class="" aria-hidden="true"><i
                                                    class="fa fa-user-plus" id="adds">新增数据</i> </span>
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- 列表展示-->
            <div class="table-responsive">
                <table class="table table-hover ">
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>标签</th>
                        <th>创建时间</th>
                        <th>创建人</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <tbody>

                    <c:forEach items="${sessionScope.list}" var="d">
                        <tr>
                            <td class="id" style="display: none">${d.id}</td>
                            <td>${d.title}</td>
                            <td>${d.label}</td>
                            <td>${d.createTime}</td>
<%--                            <td><fmt:formatDate value="${d.createTime}" pattern="yyyy-MM-dd"/></td>--%>
                            <td>${d.createUserName}</td>
                            <td>${d.status==0?'未审核':'审核通过'}</td>
                            <td>
                                <c:if test="${d.status==1}">
                                    <c:if test="${d.createUserName=='admin'}">
                                        <div>
                                            <button type="button" class="btn btn-default ">
                                                <i class="fa fa-user-o">修改</i>
                                            </button>
                                        </div>
                                    </c:if>
                                    <c:if test="${d.createUserName!='admin'}">
                                        <div>
                                            <button type="button" class="btn btn-default ">
                                                <i class="fa fa-user-o">查看</i>
                                            </button>
                                        </div>
                                    </c:if>
                                </c:if>
                                <c:if test="${d.status==0}">
                                    <div class="btn-group">
                                    <button type="button" class="btn btn-default ">
                                        <i class="fa fa-user-o">修改</i>
                                    </button>
                                    <c:if test="${sessionScope.username=='admin'||sessionScope.create_user_id==d.createUserId}">
                                        <button type="button" class="btn btn-danger">
                                            <i class="fa fa-user-times">删除</i>
                                        </button>
                                        </div>
                                    </c:if>
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="jump" style="text-align: right">
                    <form action="<%=request.getContextPath()%>/teachingQuestions/getByLabelToPage" method="get">
                            <span class="jump_text">共有<%=(int) session.getAttribute("total") / 10 +
                                    ((int) session.getAttribute("total") % 10 != 0 ? 1 : 0)%>页,<%=(int) session
                                    .getAttribute("total") %>条记录,跳到
                                <input id="labels" type="text" name="label" style="display: none"
                                       value="<%= session.getAttribute("label")%>">
                                <input type="text" name="pageNum" style="width: 30px"
                                       id="jumpPage"
                                       onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');">页
                                <input type="submit" class="btn btn-primary btn-xs"
                                       value="GO"/>
                            </span>
                    </form>
                </div>
            </div>
            <!-- 底部页码部分 -->
            <jsp:include page="pagination.jsp" flush="true"/>
        </div>
    </div>
</div>
<!-- 底部页脚部分 -->
<jsp:include page="foot.jsp" flush="true"/>
<script>
    $(document).ready(function () {

        $("#emptys").click(function () {
            $.get("/courseware/vipTeachingQuestions/clear", function () {
                window.location.href = "http://localhost:8080/courseware/insert.jsp"
            })

        })
        $(".btn-danger").click(function () {
            var parentRow = $(this).closest("tr"); // 获取按钮所在的行
            var id = parentRow.find("td:eq(0)").text();  // 找到第1个数据列
            alert("确定要删除？")
            console.log(id)
            $.post("/courseware/teachingQuestions/delete/" + id, function () {
                window.location.href = "http://localhost:8080/courseware/insert.jsp"
            })
        })
        $(".btn-default").click(function () {
            var parentRow = $(this).closest("tr"); // 获取按钮所在的行
            var id = parentRow.find("td:eq(0)").text();  // 找到第1个数据列
            console.log(id)
            $.get("/courseware/teachingQuestions/getById/" + id, function () {
                window.location.href = "http://localhost:8080/courseware/update.jsp"
            })
        })
        $("#adds").click(function () {
            window.location.href = "http://localhost:8080/courseware/add.jsp"
        })
    })
</script>
</body>
</html>
